import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALN9rP8Yi8OaetsJ8wxE/SDnQmNTuf6I\n' +
  'p08IK9YO32JdGh3oPr3xnWH7TSsBEvasM6Ad5CgOLooTvwxVkiNjdGMCAwEAAQ=='

const privateKey =
  'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAs32s/xiLw5p62wnz\n' +
  'DET9IOdCY1O5/oinTwgr1g7fYl0aHeg+vfGdYftNKwES9qwzoB3kKA4uihO/DFWS\n' +
  'I2N0YwIDAQABAkAu5hOhw+QhA+g9+2eKOSx6wHJUSbg7jbFJsTTjBZfQt1rn3L0J\n' +
  '3nTeU1L1N8X15i3Vu+DOu/ZLkOJTwuN5mSBhAiEA2T+gTRnPEs9mP+d/nSQJv5be'

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
